﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;

using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

using TimKen.App;
using TimKen.DataEntity;
using TimKen.BussLogic;
using System.Collections.Generic;
namespace TimKen.Web.Admin.PAttribute
{
    public partial class POption_Manage : TimKen.App.AdminPage
    {
        POptionManager pom = new POptionManager();

        private int OptionID = 0;

        public override string ActionCode
        {
            get
            {
                return "25";
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindResources();
                BindData();
            }
        }

        /// <summary>
        ///  绑定属性列表数据
        /// </summary>
        protected void BindData()
        {
            DataSet ds = pom.GetPageList(AspNetPager1.PageSize, AspNetPager1.CurrentPageIndex, this.LanguageID.ToString(), this.dplAttrType.SelectedValue, this.txtAttrName.Text.Trim());
            AspNetPager1.RecordCount = Convert.ToInt32(ds.Tables[1].Rows[0]["total"]);
            this.grdPOption.DataSource = ds;
            this.grdPOption.DataBind();
        }

        public void BindResources()
        {
            ListItem itemsAll = new ListItem(GetLangString("FieldType_All"), "-1");
            itemsAll.Selected = true;
            dplAttrType.Items.Add(itemsAll);
            dplAttrType.Items.Add(new ListItem(GetLangString("FieldType_TextBox"), "0"));
            dplAttrType.Items.Add(new ListItem(GetLangString("FieldType_TextArea"), "1"));
            dplAttrType.Items.Add(new ListItem(GetLangString("FieldType_Select"), "2"));
            btFilter.Text = GetLangString("Search");
            btNoFilter.Text = GetLangString("ClearSearchCondition");
        }
        protected void grdPOption_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            int optionID = Convert.ToInt32(e.CommandArgument);

            if (e.CommandName == "EditEvent")
            {
                //直接绑定属性数据
                POption optionCn = pom.GetModel(optionID, LanguageEnum.Chinese);
                POption optionEn = pom.GetModel(optionID, LanguageEnum.English);

                OptionID = optionID;
                BindData();
            }
            if (e.CommandName == "DeleteEvent")
            {
                if (pom.Delete(optionID))
                    BindData();
                else
                    Alert(pom.ValidMessage);
            }
        }

        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            BindData();
        }

        protected void btFilter_Click(object sender, EventArgs e)
        {
            AspNetPager1.CurrentPageIndex = 1;
            BindData();
        }

        protected void btNoFilter_Click(object sender, EventArgs e)
        {
            dplAttrType.SelectedValue = "-1";
            AspNetPager1.CurrentPageIndex = 1;
            BindData();
        }

    }
}


